package d08_zuoYe;

public class MyRunable implements Runnable {

    int num = 100;

    @Override
    public void run() {
        while (true) {
            if (shendGift()) {
                break;
            }
        }
    }

    private synchronized boolean shendGift() {
        if (num > 10) {
            System.out.println(Thread.currentThread().getName()+"正在发送第"+num+"个礼物···");
            num--;
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
               throw  new RuntimeException(e);
            }
            return  false;
        }else {
            System.out.println(Thread.currentThread().getName()+"没有礼物了···");
            return true;
        }
    }


}
